package test06;

import java.util.Stack;


public class Solution {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int len = pushV.length;
        int i = 0;
        for(int j = 0; j < len; j++){
            while (i < len && (stack.isEmpty() || stack.peek() != popV[j])){
                stack.pop();
                i++;
            }
            if(stack.peek() == popV[j]){
                stack.pop();
            }else{
                return false;
            }
        }
        return true;
    }
}